<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="<?php echo __ACSS__;?>/font.css">
    <link rel="stylesheet" href="<?php echo __ACSS__;?>/xadmin.css">
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="<?php echo __ALIB__;?>/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<?php echo __AJS__;?>/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="<?php echo __AJS__;?>/html5.min.js"></script>
    <script src="<?php echo __AJS__;?>/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="cat_name" class="layui-form-label">
                    <span class="x-red">*</span>栏目名</label>
                <div class="layui-input-inline">
                    <input type="text" id="cat_name" name="cat_name" required="" lay-verify="cat_name" autocomplete="off" class="layui-input" placeholder="<?php echo $data['cat_name'];?>"></div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>请输入栏目名称</div></div>
            <div class="layui-form-item">
                <label for="sort" class="layui-form-label">
                    <span class="x-red">*</span>排序</label>
                <div class="layui-input-inline">
                    <input type="text" id="sort" name="sort" required="" lay-verify="sort" autocomplete="off" class="layui-input" placeholder="<?php echo $data['sort'];?>"></div>
            </div>
            <div class="layui-form-item">
                <label for="status" class="layui-form-label">
                    <span class="x-red">*</span>状态</label>
                <div class="layui-input-inline">
                <input type="radio" name="status" value="1" title="启用" <?php if($data['status'] == 1){ echo 'checked';} ?>>
                <input type="radio" name="status" value="0" title="禁用" <?php if($data['status'] == 0){ echo 'checked';} ?>>
                </div>
            </div>
            <label for="L_repass" class="layui-form-label"></label>
            <label class="layui-btn" onclick="save()">保存</label>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer','jquery'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            cat_name: function(value) {
                if (value.length < 3) {
                    return '栏目至少3个字符';
                }
            },
            sort:function(value) {
                if (value.length < 1) {
                    return '请输入数字排序';
                }else{
                    if (!new RegExp(/^[0-9]*$/).test(value)) {
                        return '排序仅支持数字';
                    }
                }
            }
        });
//                form.on('switch(is_open)', function(obj){
//                    var status = $("input[name='status']:checked").val();
//                    alert(status);
//                })
    });
function save() {
    var cat_name = $("#cat_name").val();
    var sort = $("#sort").val();
    var status = $("input[name='status']:checked").val();

    //发异步，把数据提交给php
    $.post("/index.php/admin/category/catEdit",{id:<?php echo $id;?>,cat_name:cat_name,sort:sort,status:status}, function (res) {
        res = JSON.parse(res);
        if (res.code==500){
            layer.alert(res.data, {
                icon: 5
            })
        }else{
            layer.alert(res.data, {
                icon: 6
            }, function() {
                //关闭当前frame
                xadmin.close();
                // 可以对父窗口进行刷新
                xadmin.father_reload();
            });
            return false;
        }
    });
};
</script>
</body>

</html>